﻿unit common;

interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls,dxBar, Forms,
  cxGridCustomTableView,cxGridTableView, cxGridDBTableView,cxGridCustomView,cxGrid,
  FIBDatabase;

  //function FindChild(AName :string) :TForm;
  function GetSelected(FieldName :string; grd :TcxGrid) :string;
  procedure AddButton(Aname,capt :string);
  procedure RemoveBtn (AName :string);
  var ColorSheme :string;
  MainDb : TFIBDatabase;
implementation

uses mainFrm, DModule;

function GetSelected(FieldName :string; grd :TcxGrid) :string;
var
    Column: TcxGridDBColumn;
    ColumnIndex: Integer;
    RecordIndex: Integer;
    Text: String;
begin
 Column := TcxGridDBTableView(grd.FocusedView).GetColumnByFieldName(FieldName);
 ColumnIndex := Column.Index;
 RecordIndex := TcxGridDBTableView(grd.FocusedView).
                                    DataController.FocusedRecordIndex;
 Text := TcxGridDBTableView(grd.FocusedView).DataController.
                                 GetDisplayText (RecordIndex,ColumnIndex);
 Result:=Text;
end;


procedure RemoveBtn (AName :string);
 var i :Integer;
 s :string;
begin
 with MainForm do
 begin
  with barmen1 do
  begin
    BeginUpdate;
    try
     for I := 0 to bar2.ItemLinks.AvailableItemCount - 1 do
     begin
       if bar2.ItemLinks.Items[i].Item.Description=AName then
       begin
        bar2.ItemLinks.Delete(i);
        Break;
       end;
     end;
    finally
      EndUpdate;
    end;
  end;
 end;
end;

procedure AddButton(Aname,capt :string);
begin
 with MainForm do
 begin
  with barmen1 do
  begin
    BeginUpdate;
    try
      with bar2.ItemLinks.AddButton do
      begin
        Item.Caption := capt;
        Item.Glyph:=GetFormImage;
        Item.Description:=Aname;
        (Item as TdxBarButton).PaintStyle:=psCaption;
        UserPaintStyle :=psCaption;
        //Item.OnClick:=GetForm;
      end;
    finally
      EndUpdate;
    end;
  end;
 end;
end;



end.
